home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Updates / Librarys / zee_ini_library / Sources / Asm / INI_Example.s
Text File  |  1999-03-21  |  21KB  |  625 lines

  1. *************************************************
  2. ***  Complex example program for INI library  ***
  3. ***          © 1999 by Basty/Seasons          ***
  4. ***   This program demonstrates the powerful  ***
  5. ***       functions of the INI library        ***
  6. ***             Assembler version             ***
  7. ***    Devpac 3.18 was used for development   ***
  8. *************************************************
  9.  
  10.     include    "exec/types.i"
  11.     include    "exec/libraries.i"
  12.     include    "exec/exec_lib.i"
  13.     include    "libraries/dosextens.i"
  14.     include    "libraries/ini_lib.i"
  15.     include    "intuition/screens.i"
  16.     include    "intuition/intuition.i"
  17.     include    "intuition/intuitionbase.i"
  18.     include    "intuition/intuition_lib.i"
  19.     include    "graphics/graphics_lib.i"
  20.     include    "graphics/rastport.i"
  21.  
  22.     moveq    #20,d7                    * Set FAIL error mark
  23.     moveq    #31,d0                    * Version 31.00 of ini.library
  24.     lea    ININame(pc),a1                * Load A1 with ini.library
  25.     move.l    4.w,a6
  26.  
  27.     jsr    _LVOOpenLibrary(a6)            * Open ini.library
  28.  
  29.     move.l    d0,_INIBase                * Store ini.library base to INIBase
  30.     beq    OpenINIError                * Exit if error
  31.  
  32.     moveq    #0,d0                    * Any version of intuition.library
  33.     lea    IntName(pc),a1                * Load A1 with intuition.library
  34.  
  35.     jsr    _LVOOpenLibrary(a6)            * Open intuition.library
  36.  
  37.     move.l    d0,_IntBase                * Store intuition.library base to IntBase
  38.  
  39.     moveq    #0,d0                    * Any version of graphics.library
  40.     lea    GfxName(pc),a1                * Load A1 with graphics.library
  41.  
  42.     jsr    _LVOOpenLibrary(a6)            * Open graphics.library
  43.  
  44.     move.l    d0,_GfxBase                * Store graphics.library base to GfxBase
  45.  
  46.     move.l    _IntBase(pc),a0            * Get first screen (WB screen)
  47.     move.l    ib_FirstScreen(a0),WBScreen+8
  48.  
  49.     lea    DefaultINI(pc),a0            * Load default INI file
  50.     lea    ExampleINI(pc),a1            * Open :Example.INI file
  51.     move.l    #DefaultLen,d0            * Length of it in D0
  52.  
  53.     CALLINIB    iniOpenDefault        * Open INI file/Create default INI file
  54.  
  55.     move.l    d0,DefINIFile            * Store loaded iniFile
  56.     beq    CloseINI                    * Error -> close everything and end
  57.  
  58.     moveq    #1,d6                    * Start with first screen
  59. LoopReadScr:    lea    ScreenNum(pc),a0    * Store to screen number
  60.     move.l    d6,d0                    * Current screen number
  61.     moveq    #INI_FORMAT_DEC,d1        * Use standard decimal format
  62.     moveq    #0,d2                    * No given length, as long as the string
  63.                                     * becomes.
  64.     moveq    #" ",d3                    * Use SPACE character as zero separator
  65.  
  66.     CALLINIB    iniIntToStr            * Convert screen number
  67.  
  68.     move.l    DefINIFile(pc),a0
  69.     lea    ScreenContext(pc),a1        * Find the context
  70.     moveq    #0,d0                    * No flags (case insensitive search)
  71.  
  72.     CALLINI    iniFindContext            * Search for context
  73.  
  74.     tst.l    d0                        * Found?
  75.     beq    LoopReadScrDone                * No -> end of search
  76.     move.l    d0,CurrentContext        * Store current ContextStr
  77.  
  78.     lea    NewScreenStr(pc),a5            * NewScreen structure to A5
  79.     move.l    DefINIFile(pc),a0
  80.     lea    ScreenContext(pc),a1        * Get current screen context name
  81.     lea    LeftEdgeName(pc),a2            * Get left edge value
  82.     moveq    #0,d0                    * Default left edge is 0
  83.     moveq    #0,d1                    * No flags (case insensitive search)
  84.  
  85.     CALLINI    iniReadLong
  86.  
  87.     move.w    d0,(a5)                    * Store left edge into screen structure
  88.  
  89.     move.l    DefINIFile(pc),a0
  90.     lea    ScreenContext(pc),a1        * Get current screen context name
  91.     lea    TopEdgeName(pc),a2            * Get top edge value
  92.     moveq    #0,d0                    * Default top edge is 0
  93.     moveq    #0,d1                    * No flags (case insensitive search)
  94.  
  95.     CALLINI    iniReadLong
  96.  
  97.     move.w    d0,ns_TopEdge(a5)        * Store top edge into screen structure
  98.  
  99.     move.l    DefINIFile(pc),a0
  100.     lea    ScreenContext(pc),a1        * Get current screen context name
  101.     lea    WidthName(pc),a2            * Get width value
  102.     move.l    #640,d0                    * Default width is 640
  103.     moveq    #0,d1                    * No flags (case insensitive search)
  104.  
  105.     CALLINI    iniReadLong
  106.  
  107.     move.w    d0,ns_Width(a5)            * Store width into screen structure
  108.  
  109.     move.l    DefINIFile(pc),a0
  110.     lea    ScreenContext(pc),a1        * Get current screen context name
  111.     lea    HeightName(pc),a2            * Get height value
  112.     move.l    #256,d0                    * Default height is 256
  113.     moveq    #0,d1                    * No flags (case insensitive search)
  114.  
  115.     CALLINI    iniReadLong
  116.  
  117.     move.w    d0,ns_Height(a5)        * Store height into screen structure
  118.  
  119.     move.l    DefINIFile(pc),a0
  120.     lea    ScreenContext(pc),a1        * Get current screen context name
  121.     lea    DepthName(pc),a2            * Get depth value
  122.     moveq    #4,d0                    * Default depth is 4
  123.     moveq    #0,d1                    * No flags (case insensitive search)
  124.  
  125.     CALLINI    iniReadLong
  126.  
  127.     move.w    d0,ns_Depth(a5)            * Store depth into screen structure
  128.  
  129.     move.l    DefINIFile(pc),a0
  130.     lea    ScreenContext(pc),a1        * Get current screen context name
  131.     lea    ViewModesName(pc),a2        * Get view mode value
  132.     move.l    #$8000,d0                * Default view modes are 0x8000
  133.     moveq    #0,d1                    * No flags (case insensitive search)
  134.  
  135.     CALLINI    iniReadLong
  136.  
  137.     move.w    d0,ns_ViewModes(a5)        * Store view mode into screen structure
  138.  
  139.     move.l    DefINIFile(pc),a0
  140.     lea    ScreenContext(pc),a1        * Get current screen context name
  141.     lea    TitleName(pc),a2            * Get screen title
  142.     lea    DefaultScrTitle(pc),a3        * Default screen title
  143.     moveq    #0,d0                    * No flags (case insensitive search)
  144.  
  145.     CALLINI    iniReadStr
  146.  
  147.     move.l    d0,ns_DefaultTitle(a5)    * Store title into screen structure
  148.  
  149.     moveq    #256/4-1,d0                * Copy all 256 default colors to
  150.     moveq    #0,d1                    * updated color table
  151.     lea    DefaultColTab(pc),a0
  152.     lea    ScrColorTable(pc),a1
  153. CopyDefColTabLoop:    move.l    (a0)+,(a1)+
  154.     move.l    (a0)+,(a1)+
  155.     dbra    d0,CopyDefColTabLoop
  156.  
  157.     move.w    ns_Depth(a5),d0            * Calculate number of colors
  158.     moveq    #1,d5                    * store 1 color
  159.     lsl.b    d0,d5                    * multiply with 2^depth
  160.     bne.s    NotGreater                * if lesser than 256 colors -> jump
  161.     move.w    #$100,d5                * set to 256 colors
  162. NotGreater:    move.l    DefINIFile(pc),a0
  163.     lea    ScreenContext(pc),a1        * Get current screen context name
  164.     lea    ColorTableName(pc),a2        * Get color table context item name
  165.     lea    ScrColorTable(pc),a3        * Get array pointer
  166.     move.l    d5,d0                    * Number of entries to read
  167.     moveq    #0,d1                    * No flags (case insensitive search)
  168.  
  169.     CALLINI    iniReadWordA            * Read color table array
  170.  
  171.     moveq    #24,d0                    * We need 24 bytes of storage buffer for
  172.                                     * each screen we open.
  173.     CALLINI    iniAllocPMem            * Allocate it using ini.library
  174.  
  175.     tst.l    d0                        * Test if error
  176.     bne.s    AllocScrOk                * No -> continue
  177.  
  178.     move.l    ns_DefaultTitle(a5),a0    * Deallocate title string (don't forget!)
  179.  
  180.     CALLINIB    iniFreeNameStr        * Deallocate name string
  181.     bra    CloseINI                    * Close INI file
  182.  
  183. AllocScrOk:    lea    Screens(pc),a0        * Add the structure to the screen list
  184.     move.l    d0,a1
  185.     move.l    4.w,a6
  186.  
  187.     jsr    _LVOAddTail(a6)                * Use exec AddTail() for this
  188.  
  189.     move.l    a5,a0                    * Now we want to open the screen
  190.     move.l    _IntBase(pc),a6            * We need intuition.library for this
  191.  
  192.     jsr    _LVOOpenScreen(a6)            * Open the screen
  193.  
  194.     move.l    Screens+MLH_TAILPRED(pc),a0    * Get last screen structure added
  195.     addq.l    #MLN_SIZE,a0
  196.     move.l    d0,(a0)+                * Store the screen for later reuse
  197.     move.l    a0,(a0)                    * Initialize node list of windows
  198.     move.l    a0,MLH_TAILPRED(a0)        * Currently there are none.
  199.     addq.l    #4,(a0)
  200.     tst.l    d0                        * Check if screen open error
  201.     bne.s    AllocScrOk2                * No -> continue
  202.  
  203.     move.l    ns_DefaultTitle(a5),a0    * Deallocate title string (don't forget!)
  204.  
  205.     CALLINIB    iniFreeNameStr        * Deallocate name string
  206.     bra    CloseINI
  207.  
  208. AllocScrOk2:    move.l    d0,a0
  209.     move.l    d5,d0                    * Read color map
  210.     lea    sc_ViewPort(a0),a0            * Screen->ViewPort
  211.     lea    ScrColorTable(pc),a1        * Load colors
  212.     move.l    _GfxBase(pc),a6            * We need graphics.library
  213.  
  214.     jsr    _LVOLoadRGB4(a6)            * Load color table
  215.  
  216.     addq.l    #1,d6                    * Increment screen counter
  217.     bra    LoopReadScr
  218.  
  219. LoopReadScrDone:    moveq    #1,d6    * Start with first window
  220. LoopReadWin:    lea    WindowNum(pc),a0    * Store to window number
  221.     move.l    d6,d0                    * Current window number
  222.     moveq    #INI_FORMAT_DEC,d1        * Use standard decimal format
  223.     moveq    #0,d2                    * No given length, as long as the string
  224.                                     * becomes.
  225.     moveq    #" ",d3                    * Use SPACE character as zero separator
  226.  
  227.     CALLINIB    iniIntToStr            * Convert window number
  228.  
  229.     addq.l    #1,d6                    * Next window
  230.     move.l    DefINIFile(pc),a0
  231.     lea    WindowContext(pc),a1        * Find the context
  232.     moveq    #0,d0                    * No flags (case insensitive search)
  233.  
  234.     CALLINI    iniFindContext            * Search for context
  235.  
  236.     tst.l    d0                        * Found?
  237.     beq    LoopReadWinDone                * No -> end of search
  238.     move.l    d0,CurrentContext        * Store current ContextStr
  239.  
  240.     lea    NewWindowStr(pc),a5            * NewWindow structure to A5
  241.  
  242.     move.l    DefINIFile(pc),a0
  243.     lea    WindowContext(pc),a1        * Get current window context name
  244.     lea    LeftEdgeName(pc),a2            * Get left edge value
  245.     moveq    #0,d0                    * Default left edge is 0
  246.     moveq    #0,d1                    * No